package com.jacen.etl.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jacen.etl.manager.ManageFilter;
import com.jacen.etl.util.HttpParamCaster;
import com.jacen.etl.util.ServletUtils;

public class LoginManagerAction {

	public static String ETL_ENTITY = "etlEntity";
	public static String USER = "user";
	
	public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String message = "";
		if (request.getMethod().equalsIgnoreCase("get")) {
			request.getRequestDispatcher("/jsp/login.jsp").forward(request, response);
			return;
		}
		String username = HttpParamCaster.getUTF8Parameter(request, "username");
		String password = HttpParamCaster.getUTF8Parameter(request, "password");
		try {
			if ("appetl".equals(username) && ManageFilter.PASSWORD.equals(password)) {
				request.getSession().setAttribute(USER, username);
				message = "{'code':1,'message':'登陆成功'}";
				ServletUtils.outputHTML(response,message);
				return;
			}else{
				message = "{'code':0,'message':'密码错误'}";
				ServletUtils.outputHTML(response,message);
				return;
			}
		} catch (Exception e) {
			message = "{'code':0,'message':'新增失败'}";
			ServletUtils.outputHTML(response,message);
			return;
		}
	}

}
